#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdlib.h>
int main()
{
    pid_t id = fork();
    if(id == 0)
    {
        int cnt =5;
        while(cnt--)
        {
            printf("%d 我是子进程，我的 pid是 %d\n",cnt,getpid());
            sleep(1);
        }
        exit(10);//子进程执行完后退出
    }
    
    int status = 0;
    int ret = waitpid(id,&status,0);
    printf("ret:%d,status:%d\n",ret,status);
    int sig = status & 0x7F;
    int code = (status >> 8) & 0xFF;
    printf("exit code = %d, signal = %d\n", code, sig);
    printf("等待子进程成功\n");

    return 0;
}
